Syllabus, Last Week and Book
R Language - Part 3
TakeHome - MidTerm Project
Additional Course - II
Next Week - R Programming
Extended Syllabus PDF
PDF - (Pg. 127-133 and 150-155)
*due date: 07/12/2020 23:59
Create a Notebook
Practice - Data Types and Structures
Today, 15:00 - 16:00
Read
Write
Plot
*# Any number with (or without) a decimal point.
a <- 3
# Sub-class of the numeric class. The suffix L tells R to store.
a <- 3L
# TRUE or FALSE - Logical Operators. < , > , == , >= , <= , != ...
a <- 3<2
# Data type consists of letters or words. String. with quotes: " … "
a <- "3"
is.XXX() and class()
Vector : The simplest data structure in R
name <- "emir"
surname <- "toker"
print(c(name,surname)) # c means “combine”
Vectors indexed using two indices instead of one.
[ row, col ]
## [1] 1 2 3
## [,1] [,2] [,3]
## [1,] 1 2 3
## [,1] [,2] [,3]
## [1,] 1 4 7
## [2,] 2 5 8
## [3,] 3 6 9
## [,1] [,2] [,3]
## [1,] 1 2 3
## [2,] 4 5 6
## [3,] 7 8 9
## [1] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
## , , 1
##
## [,1] [,2] [,3]
## [1,] 1 5 9
## [2,] 2 6 10
## [3,] 3 7 11
## [4,] 4 8 12
##
## , , 2
##
## [,1] [,2] [,3]
## [1,] 13 17 21
## [2,] 14 18 22
## [3,] 15 19 23
## [4,] 16 20 24
[ row, col, level ]
matrix <- matrix(data=1:4,nrow=2,ncol=2)
vector <- c(T,F,T,T)
var <- "hello"
data_frame <- new_df2
list <- list(matrix,vector,var,data_frame)
class(list)
str(list)
dim(list)
length(list)
Read
Write
Plot
First, we need a DATA to read.
Go to Course web page
https://emirtoker.github.io/Software_Tools_R_Github/index.html
Save .txt data to your R Project Directory
Cekmekoy_Omerli_15min.txt
https://emirtoker.github.io/Software_Tools_R_Github/index.html
Learn where you are, working directory
getwd()
List all directories
list.dirs()
List all files
list.files()
Use default dataset in R
library(help="datasets")
# for example co2
# print() and plot() co2
Two main ways
Interface of R -> Environment -> Import Dataset
Interface of R -> Environment -> Import Dataset
From Text (base)
## Read
Interface of R -> Environment -> Import Dataset
From Text (base)
Import Dataset -> From Text (readr) -> Browse
Import Dataset -> From Text (readr) -> URL Paste -> Update
Import Dataset -> From Text
Console
Try on console
- read.table("Cekmekoy_Omerli_15min.txt")
- read.delim("Cekmekoy_Omerli_15min.txt")
- read.csv("Cekmekoy_Omerli_15min.txt")
help()
OPTIONS : header =TRUE, sep = “;”
Console
url <- "https://web.itu.edu.tr/~tokerem/18397_Cekmekoy_Omerli_15min.txt"
urldata_txt <- read.table(url,
header=TRUE,
sep=";")
my_data <- read.csv("Cekmekoy_Omerli_15min.txt",
header=T,
sep=";")
View(my_data)
print(my_data)
class(my_data)
str(my_data)
attributes(my_data)
my_data$temp
attributes(my_data)
attributes(my_data)$names
attributes(my_data)$names[7]
attributes(my_data)$names[7] <- "temperature"
attributes(my_data)
attributes(my_data)$row.names
attributes(my_data)$row.names[1]
attributes(my_data)$row.names[1] <- "first"
plot()
plot(my_data)
plot(my_data[7])
plot(my_data[,7])
plot(my_data$temperature)
help(plot)
OPTIONS
plot(my_data$temperature,
type = "l", main = "My Plot",
xlab = "Time", ylab = "Temperature")
Uptade Preview
Now, plot PRESSURE parameter, in my_data
plot(my_data$pressure,
type = "l",
main = "My Plot",
xlab = "Time",
ylab = "Pressure")
How can I fix the missing data?
I will just assign NA for now. HOW?
Two ways:
my_data_NA <- read.csv("Cekmekoy_Omerli_15min.txt",
header=T,
sep=";",
na.strings=-9999.0)
View(my_data_NA)
print(my_data_NA)
How can I fix the missing data?
I will just assign NA for now. HOW?
Two ways:
my_data$pressure
my_data$pressure==-9999.0
which(my_data$pressure==-9999.0)
index <- which(my_data$pressure==-9999.0)
my_data$pressure[index]
my_data$pressure[index] <- NA
View(my_data)
print(my_data)
write.table(x=urldata_txt,
file="somenewfile.txt"
sep=";",
na="-9999",
row.names=FALSE)
write.table(x=my_data,
file="my_data.txt",
sep=";",
na=-9999.0,
row.names=FALSE)
write.table(x=my_data_NA,
file="my_data_NA.csv",
sep=";",
na="-9999",
row.names=FALSE)
write.table() and OPTIONS
foo <- c(1.1,2,3.5,3.9,4.2)
bar <- c(2,2.2,-1.3,0,0.2)
plot(foo,bar)
plot(foo,bar)
plot(foo,bar,type="l")
plot(foo,bar,type="b",main="My lovely plot",xlab="x axis label", ylab="location y")
plot(foo,bar,type="b",main="My lovely plot",xlab="",ylab="",col="red")
x <- 1:20
y <- c(-1.49,3.37,2.59,-2.78,-3.94,-0.92,6.43,8.51,3.41,-8.23,
-12.01,-6.58,2.87,14.12,9.63,-4.58,-14.78,-11.67,1.17,15.62)
plot(x,y,type="n",main="")
abline(h=c(-5,5),col="red",lty=2,lwd=2)
segments(x0=c(5,15),y0=c(-5,-5),x1=c(5,15),y1=c(5,5),col="red",lty=3,
lwd=2)
points(x[y>=5],y[y>=5],pch=4,col="darkmagenta",cex=2)
points(x[y<=-5],y[y<=-5],pch=3,col="darkgreen",cex=2)
points(x[(x>=5&x<=15)&(y>-5&y<5)],y[(x>=5&x<=15)&(y>-5&y<5)],pch=19,
col="blue")
points(x[(x<5|x>15)&(y>-5&y<5)],y[(x<5|x>15)&(y>-5&y<5)])
lines(x,y,lty=4)
arrows(x0=8,y0=14,x1=11,y1=2.5)
text(x=8,y=15,labels="sweet spot")
legend("bottomleft",
legend=c("overall process","sweet","standard",
"too big","too small","sweet y range","sweet x range"),
pch=c(NA,19,1,4,3,NA,NA),lty=c(4,NA,NA,NA,NA,2,3),
col=c("black","blue","black","darkmagenta","darkgreen","red","red"),
lwd=c(1,NA,NA,NA,NA,2,2),pt.cex=c(NA,1,1,2,2,NA,NA))
my_data_NA <- read.csv("Cekmekoy_Omerli_15min.txt",
header=T,
sep=";",
na.strings=-9999.0)
plot(my_data$temp,
type = "l",
main = "My Plot",
xlab = "Time",
ylab = "Temperature",
col = "red")
library('ggplot2')
gg <- ggplot(my_data_NA, aes(x=seq(1,121))) +
geom_line(aes(y=temp)) +
labs(title="My Time Series",
subtitle="Temperature for Omerli Station",
caption="Source: Meteorology Station",
y="Temperature",
x="Time Step")
plot(gg)
library('ggplot2')
gg <- ggplot(my_data_NA, aes(x=seq(1,121), y=temp)) +
geom_point(aes(col=temp, size=temp)) +
geom_smooth(method="loess", se=F) +
labs(title="My Time Series",
subtitle="Temperature for Omerli Station",
y="Temperature",
x="Time Step")
plot(gg)
## sta_no year month day hour minutes temp precipitation pressure
## 1 18397 2017 7 26 18 0 23.9 0.00 1003.0
## 2 18397 2017 7 26 18 15 23.9 0.00 1003.1
## 3 18397 2017 7 26 18 30 23.8 0.00 1003.2
## 4 18397 2017 7 26 18 45 23.8 0.00 1003.2
## 5 18397 2017 7 26 19 0 23.6 0.00 1003.2
## 6 18397 2017 7 26 19 15 23.2 0.00 1003.1
## 7 18397 2017 7 26 19 30 23.2 0.00 1003.1
## 8 18397 2017 7 26 19 45 23.1 0.00 1003.1
## 9 18397 2017 7 26 20 0 23.0 0.00 1003.1
## 10 18397 2017 7 26 20 15 22.8 0.00 1003.0
## 11 18397 2017 7 26 20 30 22.5 0.00 1003.0
## 12 18397 2017 7 26 20 45 22.4 0.00 1003.0
## 13 18397 2017 7 26 21 0 22.2 0.00 1003.0
## 14 18397 2017 7 26 21 15 22.3 0.00 1003.0
## 15 18397 2017 7 26 21 30 22.2 0.00 1003.1
## 16 18397 2017 7 26 21 45 21.7 0.00 1003.1
## 17 18397 2017 7 26 22 0 21.9 0.00 1003.2
## 18 18397 2017 7 26 22 15 21.7 0.00 1003.3
## 19 18397 2017 7 26 22 30 21.6 0.00 1003.3
## 20 18397 2017 7 26 22 45 22.2 0.00 1003.4
## 21 18397 2017 7 26 23 0 22.2 0.00 1003.4
## 22 18397 2017 7 26 23 15 22.1 0.00 1003.5
## 23 18397 2017 7 26 23 30 22.3 0.00 1003.4
## 24 18397 2017 7 26 23 45 22.5 0.00 1003.4
## 25 18397 2017 7 27 0 0 22.3 0.00 1003.4
## 26 18397 2017 7 27 0 15 22.2 0.00 1003.2
## 27 18397 2017 7 27 0 30 22.5 0.00 1003.2
## 28 18397 2017 7 27 0 45 22.6 0.00 1003.2
## 29 18397 2017 7 27 1 0 22.6 0.00 1003.3
## 30 18397 2017 7 27 1 15 22.6 0.00 1003.4
## 31 18397 2017 7 27 1 30 22.6 0.00 1003.2
## 32 18397 2017 7 27 1 45 22.7 0.00 1003.2
## 33 18397 2017 7 27 2 0 22.6 0.00 1003.3
## 34 18397 2017 7 27 2 15 22.5 0.00 1003.2
## 35 18397 2017 7 27 2 30 22.6 0.00 1003.2
## 36 18397 2017 7 27 2 45 22.5 0.00 1003.1
## 37 18397 2017 7 27 3 0 22.5 0.00 1003.1
## 38 18397 2017 7 27 3 15 22.4 0.00 1003.0
## 39 18397 2017 7 27 3 30 22.5 0.00 1003.1
## 40 18397 2017 7 27 3 45 22.4 0.00 1003.3
## 41 18397 2017 7 27 4 0 22.5 0.00 1003.4
## 42 18397 2017 7 27 4 15 22.6 0.00 1003.5
## 43 18397 2017 7 27 4 30 23.0 0.00 1003.5
## 44 18397 2017 7 27 4 45 23.2 0.00 1003.5
## 45 18397 2017 7 27 5 0 24.2 0.00 1003.6
## 46 18397 2017 7 27 5 15 25.1 0.00 1003.5
## 47 18397 2017 7 27 5 30 25.5 0.00 1003.4
## 48 18397 2017 7 27 5 45 26.1 0.00 1003.3
## 49 18397 2017 7 27 6 0 27.1 0.00 1003.3
## 50 18397 2017 7 27 6 15 26.9 0.00 1003.3
## 51 18397 2017 7 27 6 30 27.6 0.00 1003.3
## 52 18397 2017 7 27 6 45 28.0 0.00 1003.2
## 53 18397 2017 7 27 7 0 28.4 0.00 1003.1
## 54 18397 2017 7 27 7 15 28.5 0.00 1003.1
## 55 18397 2017 7 27 7 30 29.3 0.00 1003.0
## 56 18397 2017 7 27 7 45 30.2 0.00 1002.9
## 57 18397 2017 7 27 8 0 30.1 0.00 1002.8
## 58 18397 2017 7 27 8 15 30.1 0.00 1002.8
## 59 18397 2017 7 27 8 30 30.4 0.00 1002.8
## 60 18397 2017 7 27 8 45 30.4 0.00 1002.8
## 61 18397 2017 7 27 9 0 30.8 0.00 1002.9
## 62 18397 2017 7 27 9 15 30.9 0.00 1002.8
## 63 18397 2017 7 27 9 30 31.0 0.00 1002.6
## 64 18397 2017 7 27 9 45 31.5 0.00 1002.6
## 65 18397 2017 7 27 10 0 31.2 0.00 1002.6
## 66 18397 2017 7 27 10 15 30.9 0.00 1002.4
## 67 18397 2017 7 27 10 30 30.9 0.00 1002.4
## 68 18397 2017 7 27 10 45 30.4 0.00 1002.3
## 69 18397 2017 7 27 11 0 30.4 0.00 1002.1
## 70 18397 2017 7 27 11 15 30.0 0.00 1001.9
## 71 18397 2017 7 27 11 30 29.2 0.00 1001.9
## 72 18397 2017 7 27 11 45 29.5 0.00 1001.7
## 73 18397 2017 7 27 12 0 29.4 0.00 1001.6
## 74 18397 2017 7 27 12 15 29.3 0.00 1001.3
## 75 18397 2017 7 27 12 30 29.6 0.00 1001.2
## 76 18397 2017 7 27 12 45 28.8 0.00 1001.3
## 77 18397 2017 7 27 13 0 29.0 0.00 1001.1
## 78 18397 2017 7 27 13 15 29.0 0.00 1001.2
## 79 18397 2017 7 27 13 30 29.2 0.00 1001.3
## 80 18397 2017 7 27 13 45 28.4 0.00 1001.5
## 81 18397 2017 7 27 14 0 27.8 0.00 1001.6
## 82 18397 2017 7 27 14 15 27.4 0.00 1001.6
## 83 18397 2017 7 27 14 30 26.6 0.00 1001.5
## 84 18397 2017 7 27 14 45 26.2 0.00 1001.2
## 85 18397 2017 7 27 15 0 25.8 0.00 1001.1
## 86 18397 2017 7 27 15 15 25.6 0.00 1001.0
## 87 18397 2017 7 27 15 30 25.4 0.00 1000.9
## 88 18397 2017 7 27 15 45 24.2 0.00 1001.8
## 89 18397 2017 7 27 16 0 19.2 7.01 1003.7
## 90 18397 2017 7 27 16 15 19.5 8.80 1003.2
## 91 18397 2017 7 27 16 30 20.1 0.25 1003.1
## 92 18397 2017 7 27 16 45 20.8 0.00 1003.7
## 93 18397 2017 7 27 17 0 21.2 1.13 -9999.0
## 94 18397 2017 7 27 17 15 21.4 0.02 1005.6
## 95 18397 2017 7 27 17 30 21.4 1.25 1005.4
## 96 18397 2017 7 27 17 45 21.4 2.75 1005.1
## 97 18397 2017 7 27 18 0 21.2 0.00 1005.1
## 98 18397 2017 7 27 18 15 21.0 0.00 -9999.0
## 99 18397 2017 7 27 18 30 20.8 0.00 1006.3
## 100 18397 2017 7 27 18 45 20.9 0.00 -9999.0
## 101 18397 2017 7 27 19 0 20.8 0.19 1005.7
## 102 18397 2017 7 27 19 15 20.7 0.00 1006.2
## 103 18397 2017 7 27 19 30 20.8 0.20 1003.6
## 104 18397 2017 7 27 19 45 20.8 0.22 1003.7
## 105 18397 2017 7 27 20 0 20.9 0.00 -9999.0
## 106 18397 2017 7 27 20 15 20.6 0.00 -9999.0
## 107 18397 2017 7 27 20 30 20.6 0.00 1005.1
## 108 18397 2017 7 27 20 45 20.5 0.00 1005.6
## 109 18397 2017 7 27 21 0 20.7 0.00 1005.5
## 110 18397 2017 7 27 21 15 20.8 0.00 1005.7
## 111 18397 2017 7 27 21 30 20.4 0.00 1005.6
## 112 18397 2017 7 27 21 45 20.4 0.00 1005.8
## 113 18397 2017 7 27 22 0 20.6 0.00 1005.8
## 114 18397 2017 7 27 22 15 20.5 0.00 1005.9
## 115 18397 2017 7 27 22 30 20.4 0.00 1006.0
## 116 18397 2017 7 27 22 45 20.5 0.00 1005.9
## 117 18397 2017 7 27 23 0 20.5 0.00 1005.9
## 118 18397 2017 7 27 23 15 20.6 0.00 1005.9
## 119 18397 2017 7 27 23 30 20.5 0.00 1006.0
## 120 18397 2017 7 27 23 45 20.5 0.00 1006.0
## 121 18397 2017 7 28 0 0 20.4 0.00 1006.0
## relative_humidity
## 1 94
## 2 95
## 3 96
## 4 96
## 5 96
## 6 97
## 7 97
## 8 98
## 9 98
## 10 98
## 11 98
## 12 99
## 13 99
## 14 99
## 15 99
## 16 99
## 17 99
## 18 99
## 19 99
## 20 100
## 21 100
## 22 100
## 23 100
## 24 100
## 25 100
## 26 100
## 27 100
## 28 100
## 29 100
## 30 100
## 31 100
## 32 100
## 33 100
## 34 100
## 35 100
## 36 100
## 37 100
## 38 100
## 39 100
## 40 100
## 41 100
## 42 100
## 43 100
## 44 100
## 45 100
## 46 97
## 47 84
## 48 82
## 49 79
## 50 78
## 51 78
## 52 76
## 53 76
## 54 75
## 55 73
## 56 65
## 57 57
## 58 60
## 59 53
## 60 52
## 61 51
## 62 51
## 63 50
## 64 53
## 65 52
## 66 57
## 67 58
## 68 59
## 69 60
## 70 61
## 71 65
## 72 66
## 73 67
## 74 66
## 75 68
## 76 70
## 77 68
## 78 69
## 79 69
## 80 71
## 81 72
## 82 72
## 83 77
## 84 79
## 85 80
## 86 82
## 87 84
## 88 79
## 89 99
## 90 100
## 91 100
## 92 100
## 93 100
## 94 100
## 95 100
## 96 100
## 97 100
## 98 100
## 99 100
## 100 100
## 101 100
## 102 100
## 103 100
## 104 100
## 105 100
## 106 100
## 107 100
## 108 100
## 109 100
## 110 100
## 111 100
## 112 100
## 113 100
## 114 100
## 115 100
## 116 100
## 117 100
## 118 100
## 119 100
## 120 100
## 121 100
## [1] "data.frame"
## 'data.frame': 121 obs. of 10 variables:
## $ sta_no : int 18397 18397 18397 18397 18397 18397 18397 18397 18397 18397 ...
## $ year : int 2017 2017 2017 2017 2017 2017 2017 2017 2017 2017 ...
## $ month : int 7 7 7 7 7 7 7 7 7 7 ...
## $ day : int 26 26 26 26 26 26 26 26 26 26 ...
## $ hour : int 18 18 18 18 19 19 19 19 20 20 ...
## $ minutes : int 0 15 30 45 0 15 30 45 0 15 ...
## $ temp : num 23.9 23.9 23.8 23.8 23.6 23.2 23.2 23.1 23 22.8 ...
## $ precipitation : num 0 0 0 0 0 0 0 0 0 0 ...
## $ pressure : num 1003 1003 1003 1003 1003 ...
## $ relative_humidity: int 94 95 96 96 96 97 97 98 98 98 ...
## $names
## [1] "sta_no" "year" "month"
## [4] "day" "hour" "minutes"
## [7] "temp" "precipitation" "pressure"
## [10] "relative_humidity"
##
## $class
## [1] "data.frame"
##
## $row.names
## [1] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
## [19] 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
## [37] 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
## [55] 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
## [73] 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
## [91] 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
## [109] 109 110 111 112 113 114 115 116 117 118 119 120 121
## [1] 23.9 23.9 23.8 23.8 23.6 23.2 23.2 23.1 23.0 22.8 22.5 22.4 22.2 22.3 22.2
## [16] 21.7 21.9 21.7 21.6 22.2 22.2 22.1 22.3 22.5 22.3 22.2 22.5 22.6 22.6 22.6
## [31] 22.6 22.7 22.6 22.5 22.6 22.5 22.5 22.4 22.5 22.4 22.5 22.6 23.0 23.2 24.2
## [46] 25.1 25.5 26.1 27.1 26.9 27.6 28.0 28.4 28.5 29.3 30.2 30.1 30.1 30.4 30.4
## [61] 30.8 30.9 31.0 31.5 31.2 30.9 30.9 30.4 30.4 30.0 29.2 29.5 29.4 29.3 29.6
## [76] 28.8 29.0 29.0 29.2 28.4 27.8 27.4 26.6 26.2 25.8 25.6 25.4 24.2 19.2 19.5
## [91] 20.1 20.8 21.2 21.4 21.4 21.4 21.2 21.0 20.8 20.9 20.8 20.7 20.8 20.8 20.9
## [106] 20.6 20.6 20.5 20.7 20.8 20.4 20.4 20.6 20.5 20.4 20.5 20.5 20.6 20.5 20.5
## [121] 20.4
plot(temp_data)
## [1] 19.2
## [1] 89
temp_data[89] <- NA
temp_data[which(temp_data==19.2)] <- NA
temp_data[which(temp_data==min(temp_data))] <- NA
print(temp_data)## [1] 23.9 23.9 23.8 23.8 23.6 23.2 23.2 23.1 23.0 22.8 22.5 22.4 22.2 22.3 22.2
## [16] 21.7 21.9 21.7 21.6 22.2 22.2 22.1 22.3 22.5 22.3 22.2 22.5 22.6 22.6 22.6
## [31] 22.6 22.7 22.6 22.5 22.6 22.5 22.5 22.4 22.5 22.4 22.5 22.6 23.0 23.2 24.2
## [46] 25.1 25.5 26.1 27.1 26.9 27.6 28.0 28.4 28.5 29.3 30.2 30.1 30.1 30.4 30.4
## [61] 30.8 30.9 31.0 31.5 31.2 30.9 30.9 30.4 30.4 30.0 29.2 29.5 29.4 29.3 29.6
## [76] 28.8 29.0 29.0 29.2 28.4 27.8 27.4 26.6 26.2 25.8 25.6 25.4 24.2 NA 19.5
## [91] 20.1 20.8 21.2 21.4 21.4 21.4 21.2 21.0 20.8 20.9 20.8 20.7 20.8 20.8 20.9
## [106] 20.6 20.6 20.5 20.7 20.8 20.4 20.4 20.6 20.5 20.4 20.5 20.5 20.6 20.5 20.5
## [121] 20.4
## sta_no year month day hour minutes temp precipitation pressure
## 1 18397 2017 7 26 18 0 23.9 0.00 1003.0
## 2 18397 2017 7 26 18 15 23.9 0.00 1003.1
## 3 18397 2017 7 26 18 30 23.8 0.00 1003.2
## 4 18397 2017 7 26 18 45 23.8 0.00 1003.2
## 5 18397 2017 7 26 19 0 23.6 0.00 1003.2
## 6 18397 2017 7 26 19 15 23.2 0.00 1003.1
## 7 18397 2017 7 26 19 30 23.2 0.00 1003.1
## 8 18397 2017 7 26 19 45 23.1 0.00 1003.1
## 9 18397 2017 7 26 20 0 23.0 0.00 1003.1
## 10 18397 2017 7 26 20 15 22.8 0.00 1003.0
## 11 18397 2017 7 26 20 30 22.5 0.00 1003.0
## 12 18397 2017 7 26 20 45 22.4 0.00 1003.0
## 13 18397 2017 7 26 21 0 22.2 0.00 1003.0
## 14 18397 2017 7 26 21 15 22.3 0.00 1003.0
## 15 18397 2017 7 26 21 30 22.2 0.00 1003.1
## 16 18397 2017 7 26 21 45 21.7 0.00 1003.1
## 17 18397 2017 7 26 22 0 21.9 0.00 1003.2
## 18 18397 2017 7 26 22 15 21.7 0.00 1003.3
## 19 18397 2017 7 26 22 30 21.6 0.00 1003.3
## 20 18397 2017 7 26 22 45 22.2 0.00 1003.4
## 21 18397 2017 7 26 23 0 22.2 0.00 1003.4
## 22 18397 2017 7 26 23 15 22.1 0.00 1003.5
## 23 18397 2017 7 26 23 30 22.3 0.00 1003.4
## 24 18397 2017 7 26 23 45 22.5 0.00 1003.4
## 25 18397 2017 7 27 0 0 22.3 0.00 1003.4
## 26 18397 2017 7 27 0 15 22.2 0.00 1003.2
## 27 18397 2017 7 27 0 30 22.5 0.00 1003.2
## 28 18397 2017 7 27 0 45 22.6 0.00 1003.2
## 29 18397 2017 7 27 1 0 22.6 0.00 1003.3
## 30 18397 2017 7 27 1 15 22.6 0.00 1003.4
## 31 18397 2017 7 27 1 30 22.6 0.00 1003.2
## 32 18397 2017 7 27 1 45 22.7 0.00 1003.2
## 33 18397 2017 7 27 2 0 22.6 0.00 1003.3
## 34 18397 2017 7 27 2 15 22.5 0.00 1003.2
## 35 18397 2017 7 27 2 30 22.6 0.00 1003.2
## 36 18397 2017 7 27 2 45 22.5 0.00 1003.1
## 37 18397 2017 7 27 3 0 22.5 0.00 1003.1
## 38 18397 2017 7 27 3 15 22.4 0.00 1003.0
## 39 18397 2017 7 27 3 30 22.5 0.00 1003.1
## 40 18397 2017 7 27 3 45 22.4 0.00 1003.3
## 41 18397 2017 7 27 4 0 22.5 0.00 1003.4
## 42 18397 2017 7 27 4 15 22.6 0.00 1003.5
## 43 18397 2017 7 27 4 30 23.0 0.00 1003.5
## 44 18397 2017 7 27 4 45 23.2 0.00 1003.5
## 45 18397 2017 7 27 5 0 24.2 0.00 1003.6
## 46 18397 2017 7 27 5 15 25.1 0.00 1003.5
## 47 18397 2017 7 27 5 30 25.5 0.00 1003.4
## 48 18397 2017 7 27 5 45 26.1 0.00 1003.3
## 49 18397 2017 7 27 6 0 27.1 0.00 1003.3
## 50 18397 2017 7 27 6 15 26.9 0.00 1003.3
## 51 18397 2017 7 27 6 30 27.6 0.00 1003.3
## 52 18397 2017 7 27 6 45 28.0 0.00 1003.2
## 53 18397 2017 7 27 7 0 28.4 0.00 1003.1
## 54 18397 2017 7 27 7 15 28.5 0.00 1003.1
## 55 18397 2017 7 27 7 30 29.3 0.00 1003.0
## 56 18397 2017 7 27 7 45 30.2 0.00 1002.9
## 57 18397 2017 7 27 8 0 30.1 0.00 1002.8
## 58 18397 2017 7 27 8 15 30.1 0.00 1002.8
## 59 18397 2017 7 27 8 30 30.4 0.00 1002.8
## 60 18397 2017 7 27 8 45 30.4 0.00 1002.8
## 61 18397 2017 7 27 9 0 30.8 0.00 1002.9
## 62 18397 2017 7 27 9 15 30.9 0.00 1002.8
## 63 18397 2017 7 27 9 30 31.0 0.00 1002.6
## 64 18397 2017 7 27 9 45 31.5 0.00 1002.6
## 65 18397 2017 7 27 10 0 31.2 0.00 1002.6
## 66 18397 2017 7 27 10 15 30.9 0.00 1002.4
## 67 18397 2017 7 27 10 30 30.9 0.00 1002.4
## 68 18397 2017 7 27 10 45 30.4 0.00 1002.3
## 69 18397 2017 7 27 11 0 30.4 0.00 1002.1
## 70 18397 2017 7 27 11 15 30.0 0.00 1001.9
## 71 18397 2017 7 27 11 30 29.2 0.00 1001.9
## 72 18397 2017 7 27 11 45 29.5 0.00 1001.7
## 73 18397 2017 7 27 12 0 29.4 0.00 1001.6
## 74 18397 2017 7 27 12 15 29.3 0.00 1001.3
## 75 18397 2017 7 27 12 30 29.6 0.00 1001.2
## 76 18397 2017 7 27 12 45 28.8 0.00 1001.3
## 77 18397 2017 7 27 13 0 29.0 0.00 1001.1
## 78 18397 2017 7 27 13 15 29.0 0.00 1001.2
## 79 18397 2017 7 27 13 30 29.2 0.00 1001.3
## 80 18397 2017 7 27 13 45 28.4 0.00 1001.5
## 81 18397 2017 7 27 14 0 27.8 0.00 1001.6
## 82 18397 2017 7 27 14 15 27.4 0.00 1001.6
## 83 18397 2017 7 27 14 30 26.6 0.00 1001.5
## 84 18397 2017 7 27 14 45 26.2 0.00 1001.2
## 85 18397 2017 7 27 15 0 25.8 0.00 1001.1
## 86 18397 2017 7 27 15 15 25.6 0.00 1001.0
## 87 18397 2017 7 27 15 30 25.4 0.00 1000.9
## 88 18397 2017 7 27 15 45 24.2 0.00 1001.8
## 89 18397 2017 7 27 16 0 NA 7.01 1003.7
## 90 18397 2017 7 27 16 15 19.5 8.80 1003.2
## 91 18397 2017 7 27 16 30 20.1 0.25 1003.1
## 92 18397 2017 7 27 16 45 20.8 0.00 1003.7
## 93 18397 2017 7 27 17 0 21.2 1.13 -9999.0
## 94 18397 2017 7 27 17 15 21.4 0.02 1005.6
## 95 18397 2017 7 27 17 30 21.4 1.25 1005.4
## 96 18397 2017 7 27 17 45 21.4 2.75 1005.1
## 97 18397 2017 7 27 18 0 21.2 0.00 1005.1
## 98 18397 2017 7 27 18 15 21.0 0.00 -9999.0
## 99 18397 2017 7 27 18 30 20.8 0.00 1006.3
## 100 18397 2017 7 27 18 45 20.9 0.00 -9999.0
## 101 18397 2017 7 27 19 0 20.8 0.19 1005.7
## 102 18397 2017 7 27 19 15 20.7 0.00 1006.2
## 103 18397 2017 7 27 19 30 20.8 0.20 1003.6
## 104 18397 2017 7 27 19 45 20.8 0.22 1003.7
## 105 18397 2017 7 27 20 0 20.9 0.00 -9999.0
## 106 18397 2017 7 27 20 15 20.6 0.00 -9999.0
## 107 18397 2017 7 27 20 30 20.6 0.00 1005.1
## 108 18397 2017 7 27 20 45 20.5 0.00 1005.6
## 109 18397 2017 7 27 21 0 20.7 0.00 1005.5
## 110 18397 2017 7 27 21 15 20.8 0.00 1005.7
## 111 18397 2017 7 27 21 30 20.4 0.00 1005.6
## 112 18397 2017 7 27 21 45 20.4 0.00 1005.8
## 113 18397 2017 7 27 22 0 20.6 0.00 1005.8
## 114 18397 2017 7 27 22 15 20.5 0.00 1005.9
## 115 18397 2017 7 27 22 30 20.4 0.00 1006.0
## 116 18397 2017 7 27 22 45 20.5 0.00 1005.9
## 117 18397 2017 7 27 23 0 20.5 0.00 1005.9
## 118 18397 2017 7 27 23 15 20.6 0.00 1005.9
## 119 18397 2017 7 27 23 30 20.5 0.00 1006.0
## 120 18397 2017 7 27 23 45 20.5 0.00 1006.0
## 121 18397 2017 7 28 0 0 20.4 0.00 1006.0
## relative_humidity
## 1 94
## 2 95
## 3 96
## 4 96
## 5 96
## 6 97
## 7 97
## 8 98
## 9 98
## 10 98
## 11 98
## 12 99
## 13 99
## 14 99
## 15 99
## 16 99
## 17 99
## 18 99
## 19 99
## 20 100
## 21 100
## 22 100
## 23 100
## 24 100
## 25 100
## 26 100
## 27 100
## 28 100
## 29 100
## 30 100
## 31 100
## 32 100
## 33 100
## 34 100
## 35 100
## 36 100
## 37 100
## 38 100
## 39 100
## 40 100
## 41 100
## 42 100
## 43 100
## 44 100
## 45 100
## 46 97
## 47 84
## 48 82
## 49 79
## 50 78
## 51 78
## 52 76
## 53 76
## 54 75
## 55 73
## 56 65
## 57 57
## 58 60
## 59 53
## 60 52
## 61 51
## 62 51
## 63 50
## 64 53
## 65 52
## 66 57
## 67 58
## 68 59
## 69 60
## 70 61
## 71 65
## 72 66
## 73 67
## 74 66
## 75 68
## 76 70
## 77 68
## 78 69
## 79 69
## 80 71
## 81 72
## 82 72
## 83 77
## 84 79
## 85 80
## 86 82
## 87 84
## 88 79
## 89 99
## 90 100
## 91 100
## 92 100
## 93 100
## 94 100
## 95 100
## 96 100
## 97 100
## 98 100
## 99 100
## 100 100
## 101 100
## 102 100
## 103 100
## 104 100
## 105 100
## 106 100
## 107 100
## 108 100
## 109 100
## 110 100
## 111 100
## 112 100
## 113 100
## 114 100
## 115 100
## 116 100
## 117 100
## 118 100
## 119 100
## 120 100
## 121 100
What is Function ?
A function is a set of statements organized together to perform a specific task
ex: mean() (arithmetic mean)
## [1] 2
## [1] 2
What is Function ?
A function is a set of statements organized together to perform a specific task
ex: sample() (takes a sample of the specified size from the elements of x )
## [1] 1 6
ex: sum() (returns the sum of all the values)
Create a Function
Problem: Take a sample belonged to population and sum
box <- 1:6 # This is my population in a BOX
my_samp <- sample(box, size = 2) # This is my sample, I choose two var.
sum(my_samp)
box
samp
I want to create a new function named my_roll()
my_roll <- function(box) {
box <- 1:6
my_samp <- sample(box)
sum(my_samp)
}
my_roll()
Problem: I want to define population myself, in every time. remove pre-defined population box ?
my_roll2 <- function(box) {
my_samp <- sample(box, size = 2)
sum(my_samp)
}
my_roll2(box)
box ?
box = 1:6
my_roll2(box)
my_roll2(box = 1:6)
my_roll2(1:6)
Create a Function